package org.testis.orm.refinedclasses;

import java.util.HashMap;
import org.orm.PersistentException;
import org.testis.orm.classes.T_test_stepcontainer;
import org.testis.utils.middleware.TestDesign;

/**
 * 
 * @author Cahit Emir Erel
 */
public class RepairCaseRefined extends DesignPart {

    private T_test_stepcontainer m_reference;

    public RepairCaseRefined(T_test_stepcontainer reference) {
	setReference(reference);
    }

    synchronized public RepairCaseRefined createRefinedDatabaseCopy()
	    throws PersistentException {
	return new RepairCaseRefined(createDatabaseCopy());
    }

    private T_test_stepcontainer createDatabaseCopy()
	    throws PersistentException {
	T_test_stepcontainer newContainer = new T_test_stepcontainer();
	newContainer.setContainerTypeId(this.getReference()
		.getContainerTypeId());
	newContainer.setDescription(this.getReference().getDescription());
	newContainer.setName(this.getReference().getName());
	if (newContainer.save()) {
	    return newContainer;
	} else {
	    throw new PersistentException(
		    "Unable to create database copy of Repair Case: " + this);
	}
    }

    @Override
    public String toString(TestDesignTreeNode treeNode) {
	return "Not Implemented Yet";
    }

    @Override
    public String toString() {
	return "Not Implemented Yet";
    }

    public T_test_stepcontainer getReference() {
	return m_reference;
    }

    private void setReference(T_test_stepcontainer reference) {
	if (reference == null) {
	    throw new NullPointerException();
	}
	m_reference = reference;
    }

    /**
     * 
     * @return
     * @throws NullPointerException
     */
    public String getTypeName() {
	return TestDesign.getDesignPartTypeName(this.getReference()
		.getContainerTypeId());
    }

    public int compare(Comparable source) {
	throw new UnsupportedOperationException("Not supported yet.");
    }

    public int compare(Comparable source, Comparable treeReference) {
	throw new UnsupportedOperationException("Not supported yet.");
    }

    private boolean hasSameStaticParameters(HashMap<String, Object> params,
	    Comparable treeTreference) {
	return true;
    }

    public boolean compareParameters(HashMap<String, Object> params,
	    Comparable treeTreference) {
	return hasSameStaticParameters(params, treeTreference);
    }

    public boolean hasSameRunTimeParams(HashMap<String, Object> params,
	    Comparable treeTreference) {
	return true;
    }
}
